********************************************************************************
* CREATING TABLES    
* File description: Creating table A4.2, A5.1, A5.2, A5.3, A5.4, A5.5, A5.6, A5.7 
********************************************************************************

clear all
set more off

use "use/final_data", clear

global controls age age2 female educ married kids unemployed
global area_controls avg_age share_poor share_loweduc share_selfemployed share_female avg_kids share_married lnp50 lnp20 lnhouseprice population


* Table A4.1

eststo clear
		
eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if age<=64, a(municipality) cluster(municipality) robust

		
eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if age>=65, a(municipality) cluster(municipality) robust
		
esttab using "out/tableA4_2.tex", label replace se 
		
* Table A5.1

eststo clear

eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year, a(municipality) cluster(municipality) robust

eststo: reghdfe claim_dummy yitz_agegroup lndispinc lndispinc2 $controls lnp50_agegroup population_agegroup, a(agegroup year) cluster(municipality)

eststo: reghdfe claim_dummy yitz_cfarnr lndispinc lndispinc2 $controls lnp50_cfarnr population_cfarnr, a(CfarNr year cfarnr_year) cluster(CfarNr)

eststo: reghdfe claim_dummy yitz_deso lndispinc lndispinc2 $controls lnp50_deso population_deso, a(deso year) cluster(deso) 


esttab using "out/tableA5_1.tex", label replace se
		
* Table A5.2 

eststo clear

eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 lndispinch $area_controls $controls i.year i.municipality#c.year, a(municipality) cluster(municipality) robust

eststo: reghdfe claim_dummy yitz_agegroup lndispinc lndispinc2 lndispinch $controls lnp50_agegroup population_agegroup, a(agegroup year agegroup_year) cluster(municipality)

eststo: reghdfe claim_dummy yitz_cfarnr lndispinc lndispinc2 lndispinch $controls lnp50_cfarnr population_cfarnr, a(CfarNr year cfarnr_year) cluster(CfarNr)

eststo: reghdfe claim_dummy yitz_deso lndispinc lndispinc2 lndispinch $controls lnp50_deso population_deso, a(deso year deso_year) cluster(deso) 

esttab using "out/tableA5_2.tex", label replace se 			

* Table A5.3
		
set more off
eststo clear

eststo: reg claim_dummy yitz_muni_perm lndispinc lndispinc2 i.year, cluster(municipality) robust

eststo: reg claim_dummy yitz_muni_perm lndispinc lndispinc2 $controls i.year, cluster(municipality) robust

eststo: areg claim_dummy yitz_muni_perm lndispinc lndispinc2 $area_controls $controls i.year, a(municipality) cluster(municipality) robust

eststo: areg claim_dummy yitz_muni_perm lndispinc lndispinc $area_controls $controls i.year i.municipality#c.year, a(municipality) cluster(municipality) robust


esttab using "out/tableA5_3.tex", label replace se 
				
* Table A5.4

*Sum total number of claims
sum claim_tot, d

count if claim_tot>=10

eststo clear

eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if claim_tot<10, a(municipality) cluster(municipality) robust

eststo: reghdfe claim_dummy yitz_agegroup lndispinc lndispinc2 $controls lnp50_agegroup population_agegroup if claim_tot<10, a(agegroup year) cluster(municipality)

eststo: reghdfe claim_dummy yitz_cfarnr lndispinc lndispinc2 $controls lnp50_cfarnr population_cfarnr if claim_tot<10, a(CfarNr year cfarnr_year) cluster(CfarNr)

eststo: reghdfe claim_dummy yitz_deso lndispinc lndispinc2 $controls lnp50_deso population_deso if claim_tot<10, a(deso year) cluster(deso) 

esttab using "out/tableA5_4.tex", label replace se 

* Table A5.5

eststo clear

eststo: reg claim_unpaid yitz_muni lndispinc lndispinc2 i.year, cluster(municipality) robust

eststo: reg claim_unpaid yitz_muni lndispinc lndispinc2 $controls i.year, cluster(municipality) robust

eststo: areg claim_unpaid yitz_muni lndispinc lndispinc2 $area_controls $controls i.year, a(municipality) cluster(municipality) robust

eststo: areg claim_unpaid yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year, a(municipality) cluster(municipality) robust

eststo: reghdfe claim_unpaid yitz_cfarnr lndispinc lndispinc2 $controls lnp50_cfarnr population_cfarnr, a(CfarNr year cfarnr_year) cluster(CfarNr) 


esttab using "out/tableA5_5.tex", label replace se 

		
*Table A5.6

preserve

keep municipality population year
count if mi(population)
drop if mi(population)
duplicates drop 

bys year: egen muni_size=xtile(population), nq(4)

tempfile muni_size
save `muni_size'

forv j=1(1)4 {
sum population if muni_size==`j'
}


restore

merge m:1 municipality year using `muni_size', nogen
	
	
eststo clear
		
eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if muni_size==1, a(municipality) cluster(municipality) robust
		
eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if muni_size==2, a(municipality) cluster(municipality) robust

eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if muni_size==3, a(municipality) cluster(municipality) robust

eststo: areg claim_dummy yitz_muni lndispinc lndispinc2 $area_controls $controls i.year i.municipality#c.year if muni_size==4, a(municipality) cluster(municipality) robust

		
esttab using "out/tableA5_6.tex", label replace se
				
					
* Table A5.7

eststo: reg claim_dummy yitz_muni_outliers lndispinc lndispinc2 i.year, cluster(municipality) robust

eststo: reg claim_dummy yitz_muni_outliers lndispinc lndispinc2 $controls i.year, cluster(municipality) robust

eststo: areg claim_dummy yitz_muni_outliers lndispinc lndispinc2 $area_controls $controls i.year, a(municipality) cluster(municipality) robust

eststo: areg claim_dummy yitz_muni_outliers lndispinc lndispinc $area_controls $controls i.year i.municipality#c.year, a(municipality) cluster(municipality) robust


esttab using "out/tableA5_7.tex", label replace se 
		
